package controller

import (
	"fmt"
	"gitee.com/youbeiwuhuan/gin-practice/gin-fizz/tools/render"
	"github.com/gin-gonic/gin"
	"github.com/loopfz/gadgeto/tonic"
	"github.com/wI2L/fizz"
)

// UserInfo   json 决定在swagger中显示参数名称，body决定在哪里取值
type UserInfo struct {
	Name string `json:"name" body:"name" description:"姓名" validate:"required"`
	Age  int    `json:"age" body:"age" description:"年龄" validate:"required,min=1,max=130"`
}

func AddUserGroup(baseGrp *fizz.Fizz) {
	userGrp := baseGrp.Group("/user", "用户管理", "用户管理模块接口")
	userGrp.POST("/addUser", []fizz.OperationOption{
		fizz.Summary("添加一个用户"),
		//fizz.Response("400", "Bad request", nil, nil,
		//	map[string]interface{}{"error": "fruit already exists"},
		//),
	}, tonic.Handler(addUser, 200))

}

func addUser(c *gin.Context, u *UserInfo) (render.RespData[*UserInfo], error) {
	fmt.Printf("-----------------user-------%+v", u)
	return render.OkResp(u), nil
}
